// 消耗品弹窗
import { game } from "../../../../script/game/control/game";
import { figureBase } from "../../../../script/game/control/Item/ItemBase";
import { figureType, relationType } from "../../../../script/game/gameType";
import { ListViewAdapter } from "../../../../script/util/ListView/ListViewAdapter";
import { ccs } from "../../../../script/util/services";
import { WinBase } from "../../../../script/wins/WinBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends WinBase {

    @property(ListViewAdapter)
    list: ListViewAdapter = null;

    start () {
       
        this.updateItems();
        this.touchEndEventScale(this.nodes.back, () => {
            this._close();
            ccs.winMgr.showWin('popFamilyWin');
        })
        this.registerEvent("updateRelation", () => {
            this.updateItems();
        });
    }
    updateItems() {
        //获取可做的行为
        let items = ccs.dataMgr.getRelationActions();
        let id = this._args.id;
        let figure: figureBase = game.playerMgr.bag.figureBag.getItem(id);
        this.nodes.title.getComponent(cc.Label).string = figure.data.hero.name;
        items = items.filter(val => (val.condition.relation == -1 || ( isNaN(val.condition.relation) && JSON.stringify(val.condition.relation).indexOf(figure.data.relation) != -1)) && (!val.condition.intimate||val.condition.intimate <= figure.data.intimate))
        this.list.updateItems(items);
    }
}
